from public.message import send_qq_text_msg
from public.scheduler import scheduler
from public.utils import get_web_entrance
from public.log import master_server_logger
from masterServer.masterServer import get_master_server

cache = 'http://comiee.natapp1.cc'


@scheduler.scheduled_job('cron', hour='*', misfire_grace_time=None)
def send_web_entrance():
    global cache
    last, new = cache, get_web_entrance()
    cache = new
    if last == new:
        master_server_logger.info('网址未更新')
        return
    text = f'网址已更新，新网址：{new}'
    master_server_logger.info(text)
    return get_master_server().send_to('bot', send_qq_text_msg.build(user_id=1440667228, text=text))
